package com.gjm.demo.Calculate;

import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RequestMapping("/calc")
@RestController
public class calculateController {

    @RequestMapping("/method")
    public String calc(Integer num1, Integer num2, String method) {
        if (num1 == null || num2 == null) {
            return "请输入完整数据";
        }

        if (method == null) {
            return "选择正确的计算方式";
        }

        int ret = 0;

        switch(method) {
            case "+" :
                ret = num1 + num2;
                break;
            case "-" :
                ret = num1 - num2;
                break;
            case "*" :
                ret = num1 * num2;
                break;
            case "/" :
                if (num2 == 0) {
                    return "除数不能为0";
                }
                ret = num1 / num2;
                break;
        }

        return ret + "";
    }
}
